package com.hengdu.cms.topic;

import java.io.IOException;

import com.hengdu.cms.util.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.DefaultConsumer;
import com.rabbitmq.client.Envelope;
import com.rabbitmq.client.AMQP.BasicProperties;

public class Customer2 {

	public static void main(String[] args) throws IOException {

		Connection connection = RabbitMQUtils.getConnection();
		Channel channel = connection.createChannel();

		// 通道声明交换机以及交换机类型
		channel.exchangeDeclare("topics", "topic");

		// 创建一个临时队列
		String queue = channel.queueDeclare().getQueue();

		// 绑定队列和叫花鸡,动态通配符形式 route key
		channel.queueBind(queue, "topics", "order.#");

		// 获取消费的消息
		channel.basicConsume(queue, true, new DefaultConsumer(channel) {
			@Override
			public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException {

				System.out.println("-----1---" + new String(body));
			}
		});

	}

}
